<?php
/**
 * RAI服务响应对象
 *
 * @version $Id: RaiResponse.php 312 2008-04-23 16:29:38Z iwind $
 * @package net.4kiki.rai.server
 * @since 0.0.3
 */
class RaiResponse {
	private $code;
	private $data;
	private $fault;
	private $message;
	
	/**
	 * 构造器
	 *
	 * @param integer $code 代码
	 * @param string $message 消息
	 * @param mixed $data 数据
	 * @param RaiFault $fault 错误对象
	 */
	public function __construct($code = 0, $message = null, $data = null, $fault = null) {
		$this->code = intval($code);
		$this->message = $message;
		$this->data = $data;
		$this->setFault($fault);
	}
	
	/**
	 * 设置代码
	 *
	 * @param integer $code 代码
	 */
	public function setCode($code) {
		$this->code = $code;
	}
	
	/**
	 * 设置消息
	 *
	 * @param string $message 消息
	 */
	public function setMessage($message) {
		$this->message = $message;
	}
	
	/**
	 * 设置数据
	 *
	 * @param mixed $data 数据
	 */
	public function setData($data) {
		$this->data = $data;
	}
	
	/**
	 * 设置错误对象
	 *
	 * @param RaiFault $fault 错误对象
	 */
	public function setFault($fault) {
		if ($fault === null) {
			return;
		}
		if (is_object($fault) && ($fault instanceof RaiFault)) {
			$this->fault = $fault;
		}
		else {
			throw new RaiException("fault must be an instanceof 'RaiFault'");
		}
	}
	
	/**
	 * 取得代码
	 *
	 * @return integer
	 */
	public function getCode() {
		return $this->code;
	}
	
	/**
	 * 取得消息
	 *
	 * @return string
	 */
	public function getMessage() {
		return $this->message;
	}
	
	/**
	 * 取得数据
	 *
	 * @return mixed
	 */
	public function getData() {
		return $this->data;
	}
	
	/**
	 * 取得错误
	 *
	 * @return RaiFault
	 */
	public function getFault() {
		return $this->fault;
	}
}

?>